Metadata
aliases: []
shorthands: {}
created: 2022-02-28 15:48:42
modified: 2022-02-28 15:48:42
After generating a sphere mesh, we might want to transform it into a superquadric shape. This is easy to do using the inverse parametrization of superquadric, because we can just treat the sphere as a superquadric with
This might be useful when we have a uniformly generated sphere, but we cannot do the same for a superquadric shape
Written in Python. The sphere has to have a unit radius! The arguments:
x, y, z: the coordinates of the vertices stored as in the separate arrays conventiona, b, c: the half lengths of the superquadricn1, n2: blockiness valuesimport numpy as np
def r1_sphere_to_sq(x, y, z, a, b, c, n1=2., n2=2.):
# Inverse parametrization
u = np.arcsin(np.array(z))
v = np.arctan2(np.array(y), np.array(x))
exp1 = 2.0 / n1
exp2 = 2.0 / n2
# Then map (u, v) to the superquadric
x_out = a * np.sign(np.cos(u)) * np.abs(np.cos(u)) ** exp1 * np.sign(np.cos(v)) * np.abs(np.cos(v)) ** exp2
y_out = b * np.sign(np.cos(u)) * np.abs(np.cos(u)) ** exp1 * np.sign(np.sin(v)) * np.abs(np.sin(v)) ** exp2
z_out = c * np.sign(np.sin(u)) * np.abs(np.sin(u)) ** exp1
return x_out, y_out, z_out